import request from "@/utils/request";
import { parseStrEmpty } from "@/utils/base";
export const userPrefix = "/sys/user/";

// 查询用户列表
export function listUser(query) {
  return request({
    url: userPrefix,
    method: "get",
    params: query,
  });
}

// 查询用户详细
export function getUser(id) {
  return request({
    url: userPrefix + parseStrEmpty(id) + "/",
    method: "get",
  });
}

// 新增用户
export function addUser(data) {
  return request({
    url: userPrefix,
    method: "post",
    data: data,
  });
}

// 修改用户
export function updateUser(data) {
  return request({
    url: userPrefix + `${data.id}/`,
    method: "put",
    data: data,
  });
}

// 删除用户
export function delUser(id) {
  return request({
    url: userPrefix + id + "/",
    method: "delete",
  });
}

// 用户密码重置
export function resetUserPwd(data) {
  return request({
    url: userPrefix + `${data.id}/reset_password/`,
    method: "put",
    data: data,
  });
}

// 用户状态修改
export function changeUserStatus(data) {
  return request({
    url: userPrefix + `${data.id}/change_status/`,
    method: "put",
    data: data,
  });
}

// 查询用户已授权角色列表
export function relatedRoleList(query) {
  return request({
    url: userPrefix + "get_related/",
    method: "get",
    params: query,
  });
}

// 查询用户未授权角色列表
export function unrelatedRoleList(query) {
  return request({
    url: userPrefix + "get_unrelated/",
    method: "get",
    params: query,
  });
}

// 添加用户对应角色的授权
export function authRoleAdd(data) {
  return request({
    url: userPrefix + "add_unrelated/",
    method: "put",
    data: data,
  });
}

// 取消用户对应角色的授权
export function authRoleRemove(data) {
  return request({
    url: userPrefix + "remove_related/",
    method: "put",
    data: data,
  });
}
// 查询用户个人信息
export function getUserProfile() {
  return request({
    url: userPrefix + "get_profile/",
    method: "get",
  });
}
// 修改用户个人信息
export function updateUserProfile(data) {
  return request({
    url: userPrefix + "update_profile/",
    method: "put",
    data: data,
  });
}
// 用户头像上传
export function uploadAvatar(data) {
  return request({
    url: userPrefix + "avatar/",
    method: "post",
    data: data,
  });
}
